package com.maxatime.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.maxatime.pojo.entity.ExamStudent;
import com.maxatime.service.kaoshiService;
import com.maxatime.util.MyContent;
//7月份考试题
@Controller
@RequestMapping("/kaoshi")
public class kaoshiController {
	@Autowired
	kaoshiService kaoshiService1;
	
	/**
	 * 
	 * @Title: cha   
	 * @Description: TODO(ssb 2023.9.20 考试)   
	 * @param: @return      
	 * @return: String      
	 * @throws   
	 * @author: ssb    
	 * @date:   2023年10月30日 下午3:46:41   
	 * @version V1.0
	 */
	@RequestMapping("/cha")
	public String cha() {
		return "kaoshi/kaoshi";
	}
	
	@RequestMapping("/queryData")
	@ResponseBody
	public Map<String, Object> queryData(@RequestBody ExamStudent examStudent){
		Map<String, Object> m = new HashMap<>();
		List<ExamStudent> list = kaoshiService1.listData(examStudent);
		m.put(MyContent.CODE, "0000");
		m.put(MyContent.MSG, "查询成功");
		m.put(MyContent.DATA, list);
		return m;
	}
	
	@RequestMapping("/saveData")
	@ResponseBody
	public Map<String , Object> saveData(@RequestBody ExamStudent examStudent){
		Map<String , Object > m = new HashMap<>();
		 kaoshiService1.insertSelective(examStudent);
		m.put(MyContent.CODE, "11111");
		m.put(MyContent.MSG, "新增成功");
		return m;
	}
	
	@RequestMapping("/deleteData")
	@ResponseBody
	public Map<String, Object> deleteData(@RequestBody String jsonstr){
		JSONObject json = JSONObject.parseObject(jsonstr);
		String pkId = json.getString("pkId");
		Map<String, Object> m = new HashMap<>();
		kaoshiService1.deleteByPrimaryKey(Integer.parseInt(pkId));
		m.put(MyContent.CODE, "22222");
		m.put(MyContent.MSG, "删除成功");
		return m;
	}
	
	@RequestMapping("/findpkId")
	@ResponseBody
	public Map<String , Object> findpkId(@RequestBody String jsonStr){
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		
		String pkId = jsonObj.getString("pkId");
		ExamStudent examStudent = kaoshiService1.findpkId(Integer.parseInt(pkId));
		Map<String, Object> m = new HashMap<>();
		m.put(MyContent.CODE, "3333");
		  m.put(MyContent.MSG, "反显！！");
		  m.put(MyContent.DATA, examStudent);
		return m;
	}
	
	
}
